<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>HTML TO JavaScript</title> 
	<meta name="keywords" content="" /> 
	<meta name="description" content="" /> 
 
<style type="text/css"> 
* {
	font-family: Tahoma, Verdana;
	padding: 0;
	margin: 0;
}
body {
	text-align: center;
}
#main {
	margin: 0 auto;
	width: 600px;
	text-align: left;
}
h1 {
	text-align: center;
}
h3 {
	margin: 10px 0 0 0;
}
p {
	margin: 10px 0;
}
hr {
	border: none;
	height: 1px;
	line-height: 1px;
	background: #ccc;	
}
#footer {
	font-size: 11px;
	text-align: center;
}
 
.button {
	font-weight: bold;
	padding: 5px 15px;
	border: none;
	background: #333;
	color: #FFF;
	border-top: 2px solid #999;
	border-left: 2px solid #999;
	border-right: 2px solid #000;
	border-bottom: 2px solid #000;
}
 
</style> 
 
</head> 
 
<body> 
 
	<div id="main"> 
 
		<h1>HTML转JavaScript</h1> 
		<form name="isn"> 
		  <p> 
			<textarea name="txt" rows="15" cols="100"></textarea> 
		  </p> 
		  <p align="center"> 
			<input type="button" class="button" value="Past HTML Code Above, then Click Here" onclick="smoke()" /> 
		  </p> 
		</form> 
		<br /><br /> 
 
		<h1>HTML TO JAVASCRIPT</h1> 
		<h3>HTML</h3> 
		<textarea id="oSource" rows="15" cols="100"></textarea> 
 
		<h3>JavaScript</h3> 
		<textarea id="oResult" title="双击复制" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")' rows="15" cols="100"></textarea> 
		<p align="center"> 
			<input type="button" class="button" value="Change HTML to JavaScript" onclick="change()" /> 
		</p> 
		<br /> 
		<hr /> 
 
	</div> 
 
<script type="text/javascript"> 
<!--
function $() { 
  var elements = new Array(); 
  for (var i = 0; i < arguments.length; i++) { 
	var element = arguments[i]; 
	if (typeof element == 'string') 
	  element = document.getElementById(element); 
	if (arguments.length == 1) 
	  return element; 
	elements.push(element); 
  } 
  return elements;
}
 
function change(){
	$('oResult').value="document.writeln(\""+oSource.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
}
 
var spliff="";
var medical='"';
var pot="'";
var weed="\r";
function smoke(){
spliff=document.isn.txt.value;
if (spliff==""){
alert("请输入HTML代码 There is no code pasted the text window");
}
else{
htmlPar();
}
}
function htmlPar(){
document.isn.txt.value="转换中Converting......";
pos=spliff.indexOf(medical);
pos1=spliff.indexOf(pot);
if ((pos>-1)&&(pos1>-1)){
reWrt();
}
if (pos>-1){
qt=pot;
}
else{
qt=medical;
}
while (spliff.indexOf(weed)>-1){
lc=spliff.indexOf(weed);
spliff=spliff.substring(0,lc)+" "+spliff.substring(lc+1,spliff.length);
}
nspliff="<script type="+qt+"text/javascript"+qt+">"+weed
+"<!--"+weed
+" document.write("+qt+spliff.substring(0,36)+qt;
spliff=spliff.substring(36,spliff.length);
spliffl=spliff.length
pp=50;
if (pp>spliffl) {
pp=spliffl;
}
while (spliffl>0){
nspliff+="\r +"+qt+spliff.substring(0,pp)+qt;
spliff=spliff.substring(pp,spliffl);
spliffl=spliff.length;
if (pp>spliffl){
pp=spliffl;
}
}
nspliff+=");"+weed+"// -->"+weed+"<\/sc"
+"ript>";
document.isn.txt.value=nspliff+weed+"<!-- Size: "+nspliff.length
+" bytes --> "+weed;
}
function reWrt(){
pos=-1;
while (spliff.indexOf(medical)>-1){
lc=spliff.indexOf(medical);
spliff=spliff.substring(0,lc)+pot+spliff.substring(lc+1,spliff.length);
}
}
function iA(){
this.length=iA.arguments.length;
for (var i=0;i<this.length;i++){ 
this[i]=iA.arguments[i]; 
} 
} 
 
 
//--> 
</script> 
 
</body> 
</html> 
 